package com.atguigu.gmall.product.rest;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.entity.BaseAttrInfo;
import com.atguigu.gmall.model.product.vo.BaseAttrInfoVO;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BaseAttrInfoController {

    @Autowired
    private BaseAttrInfoService baseAttrInfoService;



    /**
     * /attrInfoList/{category1Id}/{category2Id}/{category3Id}
     */
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable Long category1Id
            , @PathVariable Long category2Id
            , @PathVariable Long category3Id
    ) {
        List<BaseAttrInfo> baseAttrInfoList =  baseAttrInfoService.attrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(baseAttrInfoList);
    }

    /**
     * POST
     * /admin/product/saveAttrInfo
     */
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfoVO baseAttrInfoVO) {
        if (baseAttrInfoVO.getId() == null) {
            baseAttrInfoService.saveAttrInfo(baseAttrInfoVO);
        } else {
            baseAttrInfoService.updateAttrInfo(baseAttrInfoVO);
        }
        return Result.ok();
    }



}
